package com.example.qwen02.test;

// Copyright (c) Alibaba, Inc. and its affiliates.

import java.util.Arrays;
import java.util.Scanner;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationMessage;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalMessageItemImage;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalMessageItemText;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import io.reactivex.Flowable;

public class Main {
    //E:/Vue/photos/1.jpg
    public static void callWithLocalFile()
            throws ApiException, NoApiKeyException, UploadFileException {
        System.out.println("请输入图片的绝对路径：");
        Scanner scanner = new Scanner(System.in);
        String one = scanner.nextLine();
        String localFilePath = "file:///" + one;
        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessageItemImage userImage1 = new MultiModalMessageItemImage(
                localFilePath);

        MultiModalMessageItemText userText = new MultiModalMessageItemText("这是什么?");
        MultiModalConversationMessage userMessage = MultiModalConversationMessage.builder()
                .role(Role.USER.getValue()).content(Arrays.asList(userImage1, userText)).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .model(MultiModalConversation.Models.QWEN_VL_CHAT_V1)
                .message(userMessage)
                .build();
        Flowable<MultiModalConversationResult> result = conv.streamCall(param);
        result.blockingForEach(item -> {
            System.out.println(item);
        });
    }
    public static void main(String[] args) {
        try {
            callWithLocalFile();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

